package com.jt.common.thread;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 测试多线程任务调度
 * */
public class ScheduledExecuteServiceTests {
    public static void main(String[] args) {
        //构建一个负责任务调度的线程池对象，池中最多有三个核心现程
        ScheduledExecutorService ses = Executors.newScheduledThreadPool(3);
        //构建任务对象
        Runnable task = new Runnable() {
            @Override
            public void run() {
                String name = Thread.currentThread().getName();
                System.out.println(name + "->" + System.currentTimeMillis());
            }
        };
        //执行任务对象
        ses.scheduleAtFixedRate(task,1,1, TimeUnit.SECONDS);
    }
}
